/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_FrmFrame.h"
using namespace prs;

// TNodeFrmFrame //////////////////////////////////////////////////////////////

//
TNodeFrmFrameControl *TNodeFrmFrame::BuildControl(
  frm::control::TPanel *ParentControl
){
  TNodeFrmFrameControl *P = Control.GetValue();

  if (!P || &P->GetWindow() != &ParentControl->GetWindow()) {
    delete P; 
    P = new TNodeFrmFrameControl(ParentControl->GetWindow(),*this);
    Control.SetValue(P);
    Client.Value.Control.SetValue(P->Client);
    ParentControl->AddChildLast(P,false);
  }
  
  //////////////////////////////////////////////////////////
  Geometry.Value.UnionWidthTo (P->GetGeometry());
  Geometry.Value.UnionHeightTo(P->GetGeometry());
  //Node.Geometry.Value.UnionWAlignTo(control->Client->GetGeometry());
  //Node.Geometry.Value.UnionHAlignTo(control->Client->GetGeometry());
  Geometry.Value.UnionDirectTo(P->Client->GetGeometry());
  
  if ( Geometry.Value.Direct.GetValue()->GetEType() == TNodeFrmGeomDirect::EType_Vert ) {
  	P->Client->SetRuleWidth (new frm::geometry::TChildrenMax);
  	P->Client->SetRuleHeight(new frm::geometry::TChildrenSum);
  }
  else{
    P->Client->SetRuleHeight(new frm::geometry::TChildrenMax);
	  P->Client->SetRuleWidth (new frm::geometry::TChildrenSum);
  }
  
  return P;
}

// TRuleFrmFrame //////////////////////////////////////////////////////////

//
TRuleFrmFrame::TRuleFrmFrame(
  snt::text::TContext &Context,
  svl::TVariant &VParentNode,
  TRuleFrmChildrenBase &RChildren,
  TRuleSetNodeIdOptionally &RSetNodeIdOptionally,
  TRuleFrmGeom &RFrmGeom,
  TRuleSetStyle &RStyle
) 
:vParentNode(VParentNode)
,rGeometry(RFrmGeom)
{
  snt::text::TSequence T(Context);
  snt::text::TKeyword K(Context);
  snt::TFVoid F;
  TFuncNewNodeIntoAttrOldChildren FNewNode;
  snt::TReturn Return;

  
  this->Name(GetClassName()).Local(vParentNode)
  | K.New("frame") & FNewNode.New(vParentNode,TNodeFrmFrame()) 
    & RSetNodeIdOptionally.New() & RAttr.New() 
    & Return.New()
  ;
  
  RAttr
  | T.New("(") 
    & RAttr1.New() & F.New(this,&TRuleFrmFrame::FSetClient) & RChildren.New() 
    & T.New(")") & Return.New()
  | Return.New()
  ;

  RAttr1
  | AAttr1.New()
  ;
  AAttr1
  | RStyle.New() & AAttr1.New()
  | F.New(this,&TRuleFrmFrame::FSetGeometryFrame) & RFrmGeom.New() & AAttr1.New()
  | Return.New()
  ;
  
}